/**
 * futures : masterlink.futures.dao.GroupDao.java
 */
package masterlink.futures.dao;

import java.util.List;

import masterlink.futures.vo.Account;
import masterlink.futures.vo.GreekLimit;
import masterlink.futures.vo.Group;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import baytony.util.Util;

/**
 * TODO Write the description
 *
 * @author : tonyyang
 * Create date : 2011/10/25
 * @version 1.0.0	
 */
@Repository
@Qualifier("GreekLimitDao")
public class GreekLimitDao extends TimesTenHibernateDao<GreekLimit,Integer> {
	
	private static final String FIND_BY_ACCOUNT="select * from greeks_Limit_group where id is null and broker=? and account=?";
	private static final String FIND_BY_GROUP="select * from greeks_Limit_group where id=? and broker is null and account is null";
	private static final String DELETE_BY_GROUP="delete from greeks_Limit_group where id=?";
	
	public GreekLimit findByAccount(Account acc){
		if(acc!=null){
			List<GreekLimit> all=findBySql(FIND_BY_ACCOUNT, GreekLimit.class, acc.getId().getBroker(),acc.getId().getAcno());
			if(!Util.isEmptyList(all)){
				return all.get(0);
			}
		}
		log.trace("No GreekLimit objects foundfor acc {}.",acc);
		return null;
	}
	
	public GreekLimit findByGroup(Group g){
		if(g!=null){
			List<GreekLimit> all=findBySql(FIND_BY_GROUP, GreekLimit.class, g.getId());
			if(!Util.isEmptyList(all)){
				return all.get(0);
			} 
		}
		log.trace("No GreekLimit objects found for group {}.",g);
		return null;
	}
	
	public int deleteByGroup(Group group){
		return executeUpateQuery(DELETE_BY_GROUP, group.getId());
	}
	
}
